// TODO：请补充代码
const calcButAll = document.querySelectorAll(".calc-button");
let arr = "";
const formula = document.querySelector("#formula");
const result = document.querySelector("#result");
for (let i = 0; i < calcButAll.length; i++) {
    calcButAll[i].addEventListener("click", (e) => {
        let clickBun = e.target.innerText;
        if (clickBun != "AC" && clickBun != "=" && clickBun != "√") arr += clickBun;
        if (clickBun == "AC") {
            formula.value = "";
            result.value = "";
            arr = "";
        }
        if (clickBun == "√") {
            result.value = Math.sqrt(arr);
        }
        if (clickBun == "=") result.value = eval(arr.replaceAll('x', '*').replaceAll('÷', '/'));
        formula.value = arr; // 渲染
    });
}